package com.zengdada.authority.mapper;

import com.zengdada.authority.model.AppDictionary;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

public interface AppDictionaryMapper extends Mapper<AppDictionary> {

    @Select("<script>select * from syoauth.app_dictionary d where d.state = 1 and d.application_id in('0',#{applicationId,jdbcType=VARCHAR}) <if test=\"retainHead==false\"> and <if test=\"startIds==null\"> d.parent_id is not null </if> <if test=\"startIds!=null\"> d.id not in (<foreach collection=\"startIds\" item=\"id\" separator=\",\"> #{id,jdbcType=VARCHAR} </foreach>)</if></if> " +
            "start with <if test=\"startIds==null\"> d.parent_id is null </if>" +
            "<if test=\"startIds!=null\"> d.id in (<foreach collection=\"startIds\" item=\"id\" separator=\",\"> #{id,jdbcType=VARCHAR} </foreach>)</if> " +
            "connect by prior d.id = d.parent_id </script>")
    List<Map<String, Object>> recursiveQuery(@Param("startIds") List<String> startIds, @Param("retainHead") boolean retainHead, @Param("applicationId") String applicationId);
}